/* 
 * File:   winInterface.c
 * Author: Evan
 *
 * Created on March 27, 2010, 6:25 PM
 */

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winuser.h>
#include "Interface.h"

/*
 * 
 */
typedef unsigned short int ushort;

void sendKey(ushort, int);

JNIEXPORT void JNICALL Java_systemInterface_Interface_keyDown(JNIEnv *env, jobject obj, jint key) {
    sendKey((ushort)key, 1);
}
JNIEXPORT void JNICALL Java_systemInterface_Interface_keyUp(JNIEnv *env, jobject obj, jint key) {
    sendKey((ushort)key, 0);
}
void sendKey(ushort key, int press) {

    INPUT input={0};
    input.type = INPUT_KEYBOARD;
    if(!press) {
       input.ki.dwFlags = KEYEVENTF_KEYUP;
    }
    input.ki.wVk = key;
    INPUT inputVector[1];
    inputVector[0] = input;
    SendInput(1, inputVector, sizeof(input));
}

